package com.tianbing.adlottery.controller.systemadmin;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.validation.BindException;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.fengniu.ejb.business.IUserBusiness;
import com.fengniu.ejb.dao.ICategoryDao;
import com.fengniu.ejb.dao.IContentDao;
import com.fengniu.ejb.dao.IUserDao;
import com.fengniu.ejb.entity.Content;
import com.tianbing.adlottery.helper.SkinUtils;
import com.tianbing.adlottery.util.ControllerFormBean;

public class ApproveEditProductController extends SimpleFormController {
	static Logger logger = Logger.getLogger(ApproveEditProductController.class.getName());

	private IUserDao userDao;

	private IContentDao contentDao;

	private IUserBusiness userBusiness;

	private ICategoryDao categoryDao;

	private SkinUtils skinUtils;

	// ------------------GET Request LifeCycle------------------
	protected Object formBackingObject(HttpServletRequest request) throws Exception {
		ControllerFormBean fb = new ControllerFormBean();
		long csid = ServletRequestUtils.getLongParameter(request, "csid", -1);
		Content content = contentDao.findContentBySysId(csid);
		fb.setContent(content);
		return fb;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest,
	 *      javax.servlet.http.HttpServletResponse, java.lang.Object,
	 *      org.springframework.validation.BindException)
	 */
	protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object cmd,
			BindException ex) throws Exception {

		ModelAndView mv = new ModelAndView(this.getSuccessView());
		ControllerFormBean form = (ControllerFormBean) cmd;
		Content content = form.getContent();
		contentDao.saveContent(content);
		return mv;
	}

	protected Map referenceData(HttpServletRequest request) throws Exception {
		Map model = new HashMap();

		return model;
	}

	public void setUserDao(IUserDao userDao) {
		this.userDao = userDao;
	}

	public void setSkinUtils(SkinUtils skinUtils) {
		this.skinUtils = skinUtils;
	}

	public static void setLogger(Logger logger) {
		ApproveEditProductController.logger = logger;
	}

	public void setUserBusiness(IUserBusiness userBusiness) {
		this.userBusiness = userBusiness;
	}

	public void setContentDao(IContentDao contentDao) {
		this.contentDao = contentDao;
	}

	public void setCategoryDao(ICategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}
}
